<template>
  <div class="Broker">
    <h2>经纪人管理</h2>
    <div class="top_inputl">
      <div class="tab-inp">
        <!-- 搜索 -->
        <div class="bre">
          <b>搜索:</b>
          <el-input v-model="input" placeholder="请输入内容"></el-input>
        </div>
        <div class="bre">
          <span>状态：</span>
          <el-select v-model="value" placeholder="请选择">
            <el-option
              v-for="item in tableData"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
        <el-button type="info" @click="sousuo">查询</el-button>
        <el-button type="primary">新建</el-button>
      </div>
    </div>
    <div class="el_tab">
      <el-table :data="tableData" border width="100%"
       :header-cell-style="{background:'#efefef',color:'#606266'}"
      >
        <el-table-column prop="id" label="序号" width="60"> </el-table-column>
        <el-table-column prop="name" label="姓名" width="110">
        </el-table-column>
        <el-table-column prop="price" label="手机号" width="120">
        </el-table-column>
        <el-table-column prop="city" label="公司" width="120">
        </el-table-column>
        <el-table-column prop="price" label="新房" width="120">
        </el-table-column>
        <el-table-column prop="price" label="二手房" width="120">
        </el-table-column>
        <el-table-column prop="time" label="租房" width="180">
        </el-table-column>
        <el-table-column prop="" label="状态" width="180">
          在职
        </el-table-column>

        <el-table-column fixed="right" label="操作">
          <template slot-scope="scope">
            <el-button
              @click.native.prevent="deleteRow(scope.row.id)"
              type="text"
              size="small"
            >
              移除
            </el-button>
            <el-button
              @click.native.prevent="edit(scope.row,tableData)"
              type="text"
              size="small"
            >
              编辑
            </el-button>
             <el-button
              @click.native.prevent="qiyun(scope.row,tableData)"
              type="text"
              size="small"
            >
              启用
            </el-button>
             <el-button
              @click.native.prevent="jinyon(scope.row,tableData)"
              type="text"
              size="small"
            >
              禁用
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-dialog title="编辑" :visible.sync="dialogFormVisible">
        <el-form :model="form">
          <el-form-item label="姓名" :label-width="formLabelWidth">
            <el-input v-model="form.name" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="手机号" :label-width="formLabelWidth">
            <el-input v-model="form.price" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="公司" :label-width="formLabelWidth">
            <el-input v-model="form.city" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="租房" :label-width="formLabelWidth">
            <el-input v-model="form.time" autocomplete="off"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="editLi()">确 定</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      tableData: [],
      value: "",
      input: "",
     
       dialogFormVisible: false,
        form: {
          name: '',
          city:'',
          price:'',
          time:''
        },
        formLabelWidth: '120px'
    };
  },
  created() {
    axios.get("http://127.0.0.1:7001/getList").then((res) => {
      this.tableData = res.data.data;
    });
  },
  methods: {
    deleteRow(id) {
      axios.delete(`http://127.0.0.1:7001/delete/${id}`).then((res) => {
        this.$router.go("0");
      });
    },
    edit(row){
      this.dialogFormVisible=true;
      Object.assign(this.form,{...row})
    },
    editLi(){
      axios.put("http://127.0.0.1:7001/editList",{...this.form}).then(res=>{
        this.dialogFormVisible=false;
        this.$router.go(0)
      })
    },
    sousuo(){
      axios.get(`http://127.0.0.1:7001/getList/?keyword=${this.input}`).then(res=>{
        this.tableData=res.data.data
      })
    }
  },
};
</script>

<style scoped lang="scss">
.tab-inpute {
  width: 100%;
  height: 100px;
  display: flex;
  background: #fff;
  align-items: center;
  margin-left: 10px;
}

.cell {
  color: #000;
}
</style>
